import axios from 'axios'
import { Toast } from 'vant'

const ajax = axios.create({
  baseURL: '/api'
})

// 请求拦截
ajax.interceptors.request.use(config => {
  Toast({
    type: 'loading',
    message: '加载中',
    duration: 0
  })
  return config
})

// 响应拦截
ajax.interceptors.response.use(resp => {
  Toast.clear()
  if (resp.status === 200) {
    if (resp.data.code === 200) {
      return resp.data.data
    }
  }
  return {
    code: 0,
    msg: 'fail'
  }
})
// start是数据获取的起始索引
export const getCategory = (id, start) => ajax.get(`/tab/${id}?start=${start}`)
export const getHomeList = start => ajax.get(`/tab/1/feeds?start=${start}`)
export const getTabs = () => ajax.get('/tabs')
export const getDetail = id => ajax.get(`/detail?id=${id}`)
